using Glue;
using Glue.Converters;
using Glue.Internals;
using GlueTests.Builders;
using Xunit;

namespace GlueTests.ConverterContainerTests
{
    public class When_adding_a_converter
    {
        private readonly ConverterContainer converters;
        private readonly IConverter intStringMapping;
        private readonly IObjectMember intProperty;
        private readonly IObjectMember stringProperty;

        public When_adding_a_converter()
        {
            intStringMapping = Converting.BetweenIntAndString();
            converters = new ConverterContainer();
            converters.Add(intStringMapping);
            intProperty = PropertyBuilder.AsIntProperty().Build();
            stringProperty = PropertyBuilder.AsStringProperty().Build();
        }

        [Fact]
        public void Should_respond_converter_exists()
        {
            Assert.True(converters.CanConvert(intProperty, stringProperty)); 
        }

        [Fact]
        public void Should_respond_converter_exists_bidirectional()
        {
            Assert.True(converters.CanConvert(stringProperty, intProperty));
        }

        [Fact]
        public void Should_return_converter()
        {
            Assert.Same(intStringMapping, converters.Get(intProperty, stringProperty, RelationDirection.TwoWays));   
        }

        [Fact]
        public void Should_return_converter_bidirectional()
        {
            Assert.Same(intStringMapping, converters.Get(stringProperty, intProperty, RelationDirection.TwoWays));

        }
    }
}